using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Acms.SqlDal;

namespace Acms.Bll
{
    public class TopicFile : BaseItem
    {
        private TopicFile() : base() { }
        protected TopicFile(Hashtable table) : base(table) { }
        protected TopicFile(Hashtable table, List<TopicFile> collection) : base(table, collection) { }


        protected override Base CreateDal()
        {
            return new TopicFileDal();
        }

        public static TopicFile CreateInstance()
        {
            return new TopicFile();
        }

        private static TopicFile Get(Hashtable table)
        {
            if (table != null)
            {
                return new TopicFile(table);
            }
            else
            {
                return null;
            }
        }

        private static List<TopicFile> Get(Hashtable[] tables)
        {
            List<TopicFile> tmp = new List<TopicFile>();
            if (tables != null)
            {
                foreach (Hashtable table in tables)
                {
                    tmp.Add(new TopicFile(table, tmp));
                }
            }
            return tmp;
        }

        public static List<TopicFile> GetAllByTopicId(int topicId)
        {
            TopicFileDal dal = new TopicFileDal();
            return Get(dal.GetAllByTopicId(topicId));
        }

        public static TopicFile GetByTopicIdAndName(int topicId, string name)
        {
            TopicFileDal dal = new TopicFileDal();
            return Get(dal.GetByTopicIdAndName(topicId, name));
        }

        public static TopicFile GetById(int id)
        {
            TopicFileDal dal = new TopicFileDal();
            return Get(dal.GetById(id));
        }


        protected override void Load(Hashtable table)
        {
            id = (int)table[TopicFileDal.Fields.Id];
            topicId = (int)table[TopicFileDal.Fields.TopicId];
            fileId = (int)table[TopicFileDal.Fields.FileId];
            name = (string)table[TopicFileDal.Fields.Name];
            size = (long)table[TopicFileDal.Fields.Size];
            fileType = (int)table[TopicFileDal.Fields.FileType];
            contentType = (string)table[TopicFileDal.Fields.ContentType];
            extension = (string)table[TopicFileDal.Fields.Extension];
            width = (int)table[TopicFileDal.Fields.Width];
            height = (int)table[TopicFileDal.Fields.Height];
        }

        private int id;
        public int Id
        {
            get { return id; }
        }

        private int topicId;
        public int TopicId
        {
            get { return topicId; }
            set { topicId = value; }
        }

        private int fileId;
        public int FileId
        {
            get { return fileId; }
            set { fileId = value; }
        }

        private string name;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private long size;
        public long Size
        {
            get { return size; }
        }

        private int fileType;
        public File.FileTypes FileType
        {
            get { return (File.FileTypes)fileType; }
        }

        private string contentType;
        public string ContentType
        {
            get { return contentType; }
        }

        private string extension;
        public string Extension
        {
            get { return extension; }
        }

        private int width;
        public int Width
        {
            get { return width; }
        }

        private int height;
        public int Height
        {
            get { return height; }
        }


        public new void Update()
        {
            base.Update();
        }

        protected override void SaveChanges(ref object concurencyId, Base dal)
        {
            ((TopicFileDal)dal).Update(ref id, topicId, fileId, name, ref size, ref fileType, ref contentType, ref extension, ref width, ref height, ref concurencyId);
        }

        public new void Delete()
        {
            base.Delete();
        }

        protected override void DeleteRecord(object concurencyId, Base dal)
        {
            ((TopicFileDal)dal).Delete(id, concurencyId);
        }
    }
}
